package com.javatom.notes.common.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * 曾维录
 * http全局返回码
 */
@AllArgsConstructor
@Getter
public enum HttpReponseCodeEnum {

    SUCCESS("200", "成功"),
    MISSING_PARA("101","参数缺失"),
    //失败
    FAILED("400", "失败"),
    //未认证（签名错误）
    UNAUTHORIZED("401", "签名错误"),
    //接口不存在
    NOT_FOUND("404", "此资源不存在"),
    ERR_405("405", "请求方法不支持"),

    //服务器内部错误
    INTERNAL_SERVER_ERROR("500", "系统繁忙,请稍后再试"),
    /* 参数错误：10001-19999 */
    PARAM_ERR("10001", "参数错误 %s"),


    /* 用户错误：20001-29999*/
    USER_NOT_LOGGED_IN("20001", "用户未登录"),
    USER_LOGIN_ERROR("20002", "账号不存在或密码错误"),
    USER_ACCOUNT_FORBIDDEN("20000", "账号已被禁用"),
    ERROR_20003("20003","访问的服务需要身份认证，请引导用户到登录页"),
    ERROR_20004("20004","session已失效"),
    ERROR_20005("20005","session已失效,有可能是并发登录导致的"),

    ;
    private String code;
    private String desc;

    public static HttpReponseCodeEnum getByCode(String code) {
        for (HttpReponseCodeEnum httpReponseMsgEnum : HttpReponseCodeEnum.values()) {
            if (httpReponseMsgEnum.code.equals(code)){
                return httpReponseMsgEnum;
            }
        }
        return SUCCESS;
    }

}
